﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class ItemsCollection : ScriptableObject
{

    [System.Serializable]
    public class Configuration
    {
        public float buildTime = 0;
        public bool isCharacter;
        public float speed;
        public float attackRange = 0;
        public float defenceRange = 0;
        public float healthPoints;
        public float hitPoints;
        public float productionRate = 0;
        public string product = string.Empty;

        public float Attack, Defence, Health, Shield, Damage_feedback, Hit_rate, Critical_rate, Critical_damage, Dodge_rate, Speed, Attack_speed, Attack_range, Blind_range, Debuff_resistance;

    }


    [System.Serializable]
    public class ItemData
    {
        public int id;
        public string name;
        //缩略图
        public Texture2D thumb;
        public string modelPath;
        public GameObject model;
        public int gridSize = 4;
        public EntityType entityType = EntityType.Normal;
        public BuildingFunction buildingFunction = BuildingFunction.None;

        public Configuration configuration = new Configuration();

    }

    public enum EntityType
    {
        Normal,
        Resource,
        Defence,
        Wall,
        Decoration,
        LandUnit,
        AirUnit,
    }
    public enum BuildingFunction
    {
        None,
        ResourceProcess,
        AramyTrainer,
        MilitaryCamp,
        BuilderHut,
    }
    public List<ItemData> list = new List<ItemData>();
    // public List<ModelData> modelList = new List<ModelData>();

    public void AddNewItem()
    {
        ItemData newItemData = new ItemData();
        newItemData.id = this._GetUnusedId();
        newItemData.name = "New Item";

        this.list.Add(newItemData);
    }

    public void RemoveItem(int index)
    {
        this.list.RemoveAt(index - 1);
    }

    private int _GetUnusedId()
    {
        int id = Random.Range(1000, 9999);
        for (int index = 0; index < this.list.Count; index++)
        {
            if (id == list[index].id)
            {
                return _GetUnusedId();
            }
        }
        return id;
    }
}